package com.feicheng.iou.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.feicheng.iou.commom.ReturnCode;
import com.feicheng.iou.entity.Student;
import com.feicheng.iou.exception.SystemException;
import com.feicheng.iou.mapper.StudentMapper;
import com.feicheng.iou.pojo.PersonalDetailPOJO;
import com.feicheng.iou.service.StudentService;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author tianchunlei
 * @since 2021-06-28
 */
@Service
@Slf4j
@Setter
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService {

    @Autowired
    private StudentMapper studentMapper; //学生映射

    @Autowired
    private PersonalDetailPOJO personalDetailPOJO; //封装个人详情

    /**
     * @Author wuweinan
     * @Description 根据学生id查看学生详情.
     * @Date 2021-6-29 16:08
     * @param studentId 学生Id
     * @return Student
     */
    @Override
    @Transactional
    public Student selectStudentById(Integer studentId) {
        log.info("StudentServiceImpl的selectStudentById的方法进入");

        //调用Map获取student对象
        Student student = studentMapper.selectById(studentId);
        if(student == null){
            throw new SystemException(ReturnCode.STUDENT_NOT_EXIST);
        }


         //将获取到的student放入到Map中
        personalDetailPOJO.setStudent(student);
        log.info("StudentServiceImpl的selectStudentById的方法返回");
        return student;
    }
}
